package com.effects;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;

/**
 * @author sad
 */
public class LineBarsEffect extends BasicEffect {

    @Override
    public String getEffectName() {
        return "Line bars";
    }

    @Override
    public String getId() {
        return "lbars";
    }

    @Override
    public BufferedImage getImage(byte[] pcm) {
        double[] tSpectrum = spectrum(pcm);
        if (tSpectrum == null) {
            return null;
        }

        alphaClearingImage(image,30);
        Graphics g = image.getGraphics();
        g.setColor(Color.black);
        g.setColor(Color.green);
        tSpectrum[0]/=5;
        int height = image.getHeight();
        for (int i = 0; i < tSpectrum.length; i++) {
            g.setColor(rainbow[i]);
            double r = tSpectrum[i]*40;
            g.drawLine(i, height - (int) r, i, height);
        }

        return image;
    }
}
